<?php
	include 'search_bar.php'; 
    // http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html
?>
<div>

  <table cellpadding="0" cellspacing="0">
      <tr>
          <th class="project-name"><?php echo $this->Paginator->sort('name', 'Názov'); ?></th>
          <th class="annotation"><?php echo $this->Paginator->sort('annotation', 'Anotácia'); ?></th>
          <th class="department-name"><?php echo $this->Paginator->sort('department_id', 'Katedra'); ?></th>
          <th class="leader-name"><?php echo $this->Paginator->sort('leader_id', 'Vedúci'); ?></th>
          <th class="people">Participanti</th>
          <th class="budget"><?php echo $this->Paginator->sort('budget', 'Rozpočet'); ?></th>
          <?php if ($this->Session->check('Auth.User')){?>
            <th><?php echo $this->Paginator->sort('is_deleted', 'Neaktívny'); ?></th>
          <?php } ?>
          <th class="date"><?php echo $this->Paginator->sort('start', 'Začiatok'); ?></th>
          <th class="date"><?php echo $this->Paginator->sort('end', 'Koniec'); ?></th>
          <?php if ($this->Session->check('Auth.User')){?>
            <th class="actions">Akcie</th>
          <?php } ?>
      </tr>
         <?php foreach($data as $project){?>
      <tr class="hov<?php if($project['Project']['is_deleted'] == 1) echo ' deleted' ?>">
          <td class="first"><?php echo '<b>'.$this->Html->link($project['Project']['name'], array('admin' => false, 'controller' => 'projects', 'action' => 'detail', $project['Project']['id'])).'</b>'; ?> </td>
          <td><?php if(strlen($project['Project']['annotation']) < 100)
                      echo $project['Project']['annotation'];
                    else
                      echo substr($project['Project']['annotation'], 0, 100).'...'; ?> </td>
          <td title="<?php echo $project['Department']['fullname']; ?>"><?php echo $project['Department']['name']; ?></td>
          <td><?php echo $project['Leader']['fullname']; ?> </td>
          <td>
            <?php 
              $people = '';
              foreach ($project['Person'] as $person) {
                $people .= str_replace(' ', '&nbsp;', $person['fullname'])  . ', ';
              } 
              if ($people != '') $people = substr($people, 0, -2);
              echo '<span title="'.$people.'">' . substr($people, 0, 100) . (strlen($people) > 100 ? '...' : '') . '</span>';
            ?> 
          </td>
          <td class="budget"><?php echo $this->Number->format($project['Project']['budget'], array('places' => 2, 'before' => '', 'after' => '€', 'decimals' => ',', 'thousands' => ' ')); ?> </td>
          <?php if ($this->Session->check('Auth.User')){?>
            <td><?php if($project['Project']['is_deleted'] == 1) echo 'áno'; else echo 'nie'; ?> </td>
          <?php } ?>
          <td><?php echo $this->Time->format('d.m.Y', $project['Project']['start']); ?> </td>
          <td><?php echo $this->Time->format('d.m.Y', $project['Project']['end']); ?> </td>
          <?php if ($this->Session->check('Auth.User')){?>
            <td class="actions">
              <?php
                echo $this->Html->link(
                  $this->Html->image(BASE_URL . '/img/edit.gif', array('alt' => 'Edit')), 
                  array('admin' => true, 'controller' => 'projects', 'action' => 'edit', $project['Project']['id']),
                  array('escape' => false, 'class' => 'edit')
                );
                echo ' &nbsp; ';
                echo $this->Html->link(
                  $this->Html->image(BASE_URL . '/img/delete.gif', array('alt' => 'Deleted')), 
                  array('admin' => true, 'controller' => 'projects', 'action' => 'delete', $project['Project']['id']),
                  array('escape' => false, 'class' => 'delete'), 'Ste si istý?'
                ); 
              ?> 
            </td>
          <?php } ?>
      </tr>
      <?php } ?>
  </table>
</div>
<div class="paging">
<?php 
$params = $this->Paginator->params();
if ($params['pageCount'] > 1 ) {
// Shows the page numbers
//echo $this->Paginator->numbers();
echo ' ';
// Shows the prev link
echo $this->Paginator->prev('« Predchádzajúca', null, null, array('class' => 'disabled'));
echo ' ';
// prints X of Y, where X is current page and Y is number of pages
echo $this->Paginator->numbers();//echo $this->Paginator->counter();
echo ' ';
// Shows the next link
echo $this->Paginator->next('Nasledujúca »', null, null, array('class' => 'disabled'));
}
?>
</div>

<?php echo $this->element('limit'); ?>